package com.hmdp.utils;

import com.hmdp.entity.vo.UserVo;

/**
 * 因为ThreadLocal底层是ThreadLocalMap，当期线程Threadlocal作为key(弱引用)，user作为value(强引用)
 * jvm不会把强引用的value回收掉，所以value没被释放
 */
public class UserHolder {
    private static final ThreadLocal<UserVo> tl = new ThreadLocal<>();

    public static void saveUser(UserVo user){
        tl.set(user);
    }

    public static UserVo getUser(){
        return tl.get();
    }

    public static void removeUser(){
        tl.remove();
    }
}
